const axios = require("axios")
const fs = require("fs")
const http = require("http")
const cheerio = require("cheerio");

async function jd() {
    let options = {
        method: 'POST',
        scheme: 'https',
        url: "https://openapi.vmall.com/mcp/v1/search/queryPrd",
        headers: {
            "Accept": "*/*",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Connection": "keep-alive",
            "Content-Length": 265,
            "Content-Type": "text/plain",
            "Cookie": "TID=5b020306ba8a8b436fb80f5b01a1d69e; deviceid=5b020306ba8a8b436fb80f5b01a1d69e; cps_id=91436; cps_track_id=1630941664830_dgal8qokwcr; cartId=19df220203374542b7d6329a60def372; euid=2bf7266eab0b5e23ec0a8fe01a875295d0f5e364f160da8f; CSRF-TOKEN=80F1A1A267F14A6FFC676FE77F05FE8F6B3BB5DC6495572B; recommendflag=0; salePortal=1; HWWAFSESID=bf2b450bc8202f0cd10; HWWAFSESTIME=1630974793370",
            "CsrfToken": "80F1A1A267F14A6FFC676FE77F05FE8F6B3BB5DC6495572B",
            "Origin": "https://www.vmall.com",
            "Referer": "https://www.vmall.com/list-36",
            "Host": "openapi.vmall.com",
            "Sec-Fetch-Dest": "empty",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Site": "same-site",
            "User-Agent": " Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"

        },
        data: {
            "lang": "zh-CN",
            "country": "CN",
            "portal": 1,
            "keyword": 36,
            "pageSize": 20,
            "pageNum": 3,
            "searchSortField": 0,
            "searchSortType": "desc",
            "searchFlag": 1,
            "brandType": 0,
            "tid": "5b020306ba8a8b436fb80f5b01a1d69e",
            "PersonalizeSearch": "2",
            "searchId": "5b020306ba8a8b436fb80f5b01a1d69e"
        }

    }
    let response = await axios(options)
    var res = response.data
    // var products = res.resultDto.products
    // var arr = []

    // for (var i = 0; i < products.length; i++) {
    //     arr.push({

    //     })
    // }
    fs.writeFile("./watch2.json", JSON.stringify(res), err => {
        if (err) throw err;
        else {
            console.log("数据爬取成功");
        }

    })


}
jd()